package core;

import java.util.Collection;

/**
 * Encapsulates a set of <code>Player</code>s to whom a <code>Card</code> is visible.
 */
public class SpecialVisibility implements Visibility
{
	/**
	 * Default constructor for reflection purposes
	 */
	public SpecialVisibility() {
	}

	/**
	 * Constructs a new Visibility for a player.
	 * @param p the player that this Visibility will apply to
	 */
	public SpecialVisibility(Player p) {
		visiblePlayers.add(p);
	}

	public SpecialVisibility(Collection<Player> visiblePlayers) {
		setVisiblePlayers(visiblePlayers);
	}

	/** 
	 * Returns true if the given Player is in the set of Players
	 * to which this Visibility setting applies to.
	 * @param p a Player
	 * @return whether the Player are authorized to view this Card's attributes
	 */
	public boolean isVisibleTo(Player p) {
		return visiblePlayers.contains(p);
	}

	/**
	 * Adds a player to list of Players to which this Visibility applies to.
	 * @param p
	 */
	public void addVisiblePlayer(Player p) {
		visiblePlayers.add(p);
	}
	
	/**
	 * Returns the list of Players to which this Visibility applies.
	 */
	public Collection<Player> getVisiblePlayers() {
		return java.util.Collections.unmodifiableSet(visiblePlayers);
	}

	/**
	 * Sets the list of Players to which this Visibility applies.
	 */
	public void setVisiblePlayers(Collection<Player> visiblePlayers) {
		this.visiblePlayers.clear();
		this.visiblePlayers.addAll(visiblePlayers);
	}

	public String toString() {
		return visiblePlayers.toString();
	}

	private final java.util.Set<Player> visiblePlayers = new java.util.HashSet<Player>();
}